<template>
	<view class="user-user">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText"></block>
			<block slot="content"></block>
		</cu-custom>
		<view :style="'height:'+(winHeight-barHeight)+'px;position:relative;width:100%;'">
			<common-view :needLogin="hasLogin?'n':'y'" :zindex="997" :animationClass="animation" @closeAnimation="closeAnimation" :indicator="indicator"></common-view>
			<scroll-view class="page" refresher-background="#ffffff" scroll-y :style="'height:'+(winHeight-barHeight)+'px;'">
				<view class="UCenter-bg" style="padding:40upx 0;">
					<view class="content" hover-class="none">
						<view class="flex flex-direction align-center" style="width:120upx;">
							<view class="media" >
								<image
									:src="pageData&&pageData.avatar?(pageData.avatar):'../../static/default_member_logo.png'"
									class="png radius shadow" mode="aspectFill"></image>
							</view>
						</view>
						<view v-if="pageData" style="width:100%;padding-right:50upx;">
							<view class="name" style="width:calc( 100% - 350upx );">
								<view class="text-xl text-bold text-cut">
									<text class="text-bold">{{pageData.show_name}}</text>
								</view>
							</view>
							<view class="text-gray flex align-center justify-between" style="font-weight:normal;padding-left:10upx;">
								<text v-if="pageData.usercode"><text class="text-df">账号</text>:{{pageData.usercode}}</text>
							</view>
						</view>
						
					</view>
				</view>
				
				<view class=" cu-list menu margin-top-0 solid-top">
					<view class="cu-item arrow text-baseColor padding-right-0">
						<button class="cu-btn content" style="align-items:center;" data-url="" @click="$util.toPage">
							<text class="text-baseColor">备注和标签</text>
						</button>
					</view>
				</view>	
				<view class=" cu-list menu">
					<view class="cu-item text-baseColor padding-right-0">
						<button class="cu-btn content" style="align-items:center;" data-url="" @click="$util.toPage">
							<text class="text-baseColor">个性签名</text>
						</button>
					</view>
					<view class="cu-item text-baseColor padding-right-0">
						<button class="cu-btn content" style="align-items:center;" data-url="" @click="$util.toPage">
							<text class="text-baseColor">朋友圈</text>
						</button>
					</view>
				</view>				
				<view class=" cu-list menu">
					<view v-if="pageData && pageData.is_friend==1" class="cu-item padding-right-0">
						<button class="cu-btn content" style="align-items:center;justify-content:center;" @click="toChat">
							<text class="icon-message text-blue text-bold" style="margin:0;width:1em;font-size:1.1em;"></text>
							<text class="text-blue text-bold">发消息</text>
						</button>
					</view>
					<view v-if="pageData && pageData.is_friend==0" class="cu-item padding-right-0">
						<button class="cu-btn content" style="align-items:center;justify-content:center;" :data-url="'../../pages1/contacts/applyFriend?uid='+pageData.user_id" @click="$util.toPage">
							<text class="text-blue text-bold">添加到通讯录</text>
						</button>
					</view>
				</view>
			</scroll-view>
		</view>


	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';

	import chat from 'model/chatModel.js';
	import profileObj from 'model/profileModel.js';
	let disp = require("common/broadcast");
	let me = null;
	export default {
		data() {
			return {
				indicator: 3,
				animation:'',
				loadding: 0,
				statusbarHeight: 0,
				titleH: 0,
				systemInfo:this.systemInfo,
				shortName:this.shortName,
				barHeight:this.CustomBar,
				uid:0,
				pageData:null
			};
		},
		onLoad(option) {
			me = this;
			this.statusbarHeight = this.StatusBar;
			if (option.uid) {
				this.uid = option.uid;
				this.getData();
			} else {
				//参数错误
				uni.showModal({
					title: '系统提示',
					content: '参数错误',
					showCancel: false,
					success: function(res) {
						uni.navigateBack({
							delta: 1
						})
					}
				})
			}	
		},
		computed: {
			...mapState({
				userInfo: ({
					userModule
				}) => userModule.userInfo,
				hasLogin: ({
					userModule
				}) => userModule.hasLogin,
				appConfig: ({
					baseModule
				}) => baseModule.appConfig,
				navHeight: ({
					baseModule
				}) => baseModule.navHeight,
				winHeight: ({
					baseModule
				}) => baseModule.winHeight
			})
		},
		methods: {
			...mapMutations(['chatModule/setChatTo']),
			closeAnimation() {
				this.animation = "";
				this.indicator = 0;
			},
			getData() {
				profileObj.info(me,{
					uid:me.uid
				}).then(res => {
					me.pageData=res;
					me.$util.closeIndicator(me);
				}).catch(err => {
					console.log(err);
				});
			},
			toChat(){
				var to = {};
				to.id=me.pageData['user_id'];
				to.name=me.pageData['username'];
				to.avatar=me.pageData['avatar'];
				to.type='friend';
				me['chatModule/setChatTo'](to);
				uni.navigateTo({
					url:"../../pages1/message/chat?friendid="+to.id+"&unread=0&msgType=friend"
				});
			}
		}
	}
</script>

<style>
.cu-list+.cu-list{
	margin-top:20upx;
}
.cu-list.menu>.cu-item:after{
	left:80upx;
	overflow: hidden;
}	
</style>
